<template>
	<div class="studentAlbum">
		<div class="liveReservation_h clear">
			<router-link to="/learn/history/book">点播记录</router-link>
			<router-link to="/learn/history/live">直播记录</router-link>
			<router-link to="/learn/history/album">专辑记录</router-link>
		</div>
		<div class="footprint" v-loading="loading">
			<ul>
				<li class="classLs clear" v-for="(item,index) in albumList" :key="item.id">
					<a @click="openAlbum(item)" class="classLs_img">
						<img :src="BASE_URL+item.picture" :onerror="errorImg">
					</a>
					<div class="classLs_info">
						<div class="classLs_1 clear">
							<a @click="openAlbum(item)">{{item.name}}</a>
							<div class="resource_ioperation fr">
								<el-popover placement="bottom" width="" popper-class="ioperation_hover" trigger="hover">
									<ul class="r_ioperation">
										<li @click="removeData(item.album_id)">删除</li>
									</ul>
									<i slot="reference" class="el-icon-arrow-down"></i>
								</el-popover>
							</div>
						</div>
						<div class="classLs_2">
							<strong>{{item.videocount}}门课程</strong>
							<span v-for="(item2, index2) in item.keyword" :key="item2">{{item2}}</span>
						</div>
					</div>
				</li>
			</ul>
		</div>
		<div class="pageBox" v-show="total_number > page_size">
			<el-pagination @current-change="change_page" :page-size="page_size" :current-page="page_index" layout="prev, pager, next" :total="total_number">
			</el-pagination>
		</div>
		<div class="dependent" v-show="placeholder">
			<i class="ipm image_nofound"></i>
			<p>
				还没发现任何相关的内容哦~
			</p>
		</div>
	</div>
</template>
<script>
export default {
	data() {
		return {
			albumList: [],
			total_number: 0,
			page_size: this.$g.page_size,
			page_index: 1,
			errorImg: 'this.src="' + require('../../../public/images/image20.png') + '"',
			placeholder: false,
			loading: true,
		}
	},
	created() {
		this.getAlbum()
	},
	methods: {
		/*
			跳转到优课专辑模块查看视频
		 */
		openAlbum(item) {

			let host = sessionStorage.getItem('host')
			let redirectParams = sessionStorage.getItem('redirect_params')
			let link = `${this.BASE_URL}${redirectParams}&host=${host}&routerUrl=/home/albumDetail&id=${item.album_id}`
			window.open(link)
		},
		getAlbum() {
			let success = (res => {
				let data = res.data;
				this.albumList = data.data;
				this.total_number = data.data_sum;
				this.page_index = parseInt(data.page_index)
				for (var i = 0; i < this.albumList.length; i++) {
					if (this.albumList[i].keyword != '') {
						this.albumList[i].keyword = JSON.parse(this.albumList[i].keyword)
					}
				}	

				this.loading = false;
				this.placeholder =  this.albumList.length === 0 ? true : false
			});
			this.$ajax({
				url: 'api/album/user_album_list',
				method: 'get',
				params: {
					userid: this.$g.user_id,
					page_index: this.page_index,
					page_size: this.page_size
				},
				func: {
					success: success
				}
			})
		},
		change_page(val) {
			this.page_index = val;
			this.getAlbum()
		},
		//删除
		removeData(id) {
			this.$confirm('此操作是否继续?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning',
				customClass: 'confirm-them'
			}).then(() => {

				let success = (res => {
					this.$message.success(res.msg)
					this.getAlbum()
				})
				this.$ajax({
					url: 'api/album/delete_album_user',
					method: 'delete',
					params: {
						albumid: id,
						user_id: this.$g.user_id
					},
					func: {
						success: success
					}
				})
			}).catch(() => {});
		},
	}
}
</script>